import moment from 'moment'

/**
 * 
 * 返回所需日期的时间戳
 * @param {string} quickName 想要获取的时间名称
 * @param {Date} startDate 现在显示的开始时间
 * @param {Date} endDate 现在显示的结束时间
 */
const quickDateHelper = (quickName, startDate, endDate) => {
  let theoryToday = startDate ? startDate : new Date(moment().valueOf())
  let weekOfday = parseInt(moment(theoryToday).format('d'))       // 计算今天是这周第几天 周日为一周中的第一天

  switch (quickName) {
    case '全部':
      startDate = ''
      endDate = ''
      break
    case '上一周':
      startDate = moment(theoryToday).subtract(6 + weekOfday, 'days').valueOf()
      endDate = moment(startDate).add(6, 'days').valueOf()
      break;
    case '本周':
      weekOfday = parseInt(moment().format('d'))
      startDate = moment().subtract(weekOfday - 1, 'days').valueOf()
      endDate = moment().subtract(weekOfday - 7, 'days').valueOf()
      break;
    case '下一周':
      weekOfday = parseInt(moment(theoryToday).format('d'))
      startDate = moment(theoryToday).add(8 - weekOfday, 'days').valueOf()
      endDate = moment(startDate).add(6, 'days').valueOf()
      break;
    case '上一月':
      startDate = startDate ? moment(startDate).subtract(1, 'month').startOf('month').valueOf() : moment().subtract(1, 'month').startOf('month').valueOf()
      endDate = moment(startDate).endOf('month').valueOf()
      break;
    case '本月':
      startDate = moment().startOf('month').valueOf()
      endDate = moment().endOf('month').valueOf()
      break;
    case '下一月':
      startDate = startDate ? moment(startDate).add(1, 'month').startOf('month').valueOf() : moment().add(1, 'month').startOf('month').valueOf()
      endDate = moment(startDate).endOf('month').valueOf()
      break;
    case '上一年':
      startDate = startDate ? moment(startDate).subtract(1, 'year').startOf('year').valueOf() : moment().subtract(1, 'year').startOf('year').valueOf()
      endDate = moment(startDate).endOf('year').valueOf()
      break;
    case '本年':
      startDate = moment().startOf('year').valueOf()
      endDate = moment().endOf('year').valueOf()
      break;
    case '下一年':
      startDate = startDate ? moment(startDate).add(1, 'year').startOf('year').valueOf() : moment().add(1, 'year').startOf('year').valueOf()
      endDate = moment(startDate).endOf('year').valueOf()
      break;
  }

  return { startDate, endDate }
}

export {
  quickDateHelper
}